﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class mwc_admin_controls_editcontent : System.Web.UI.UserControl
{
    string conn;
    string article_id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            conn = ConfigurationSettings.AppSettings["mwc_con"];
            article_id = Request.QueryString.Get("id");
            SqlConnection scn = new SqlConnection(conn);
            scn.Open();
            string query = "SELECT * FROM mwc_content WHERE id = " + article_id;
            SqlCommand scmd = new SqlCommand(query,scn);
            SqlDataReader sdr = scmd.ExecuteReader();
            try
            {
                while (sdr.Read())
                {
                    edit_title.Text = sdr["title"].ToString();
                    edit_introtext.Text = sdr["introtext"].ToString();
                    edit_fulltext.Text = sdr["fulltext"].ToString();
                    edit_enable.Checked = (bool)sdr["enable"];
                }
            }
            finally {
                sdr.Close();
            }
            scn.Close();
        }
    }
    protected void updateContent(object ob, EventArgs e)
    {
        conn = ConfigurationSettings.AppSettings["mwc_con"];
        SqlConnection scn = new SqlConnection(conn);
        scn.Open();
        string query = "UPDATE mwc_content SET title = '" + edit_title.Text + "', introtext = '" + edit_introtext.Text + "', fulltext = '" + edit_fulltext.Text + "', enable = '" + edit_enable.Checked.ToString() + "' WHERE id = " + Request.QueryString.Get("id"); ;
        SqlCommand scmd = new SqlCommand(query,scn);
        try
        {
            scmd.ExecuteNonQuery();
        }
        finally {
            scn.Close();
        }
        Redirect2List("Update Successfully");
    }
    protected void Redirect2List(string msg)
    {
        Response.Redirect("~/mwc_admin/Panel.aspx?option=listcontent&msg="+msg);
    }
}
